﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lg_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var username = lg.UserName.Trim();
            var password = lg.Password.Trim();

            var sql = string.Format("select * from users where username='{0}' and password='{1}'",username,password);
            var dt = DbHelper.GetDataTable(sql);
            if (dt.Rows.Count == 1)
            {
                //验证通过，允许跳转
                var row = dt.Rows[0];
                var isActived = (bool)row.ItemArray[3];
                var isDeleted = (bool)row.ItemArray[4];
                if (isDeleted)
                {
                    //己删除
                    lblComment.Text = "当前账号已经删除或注销，如有疑问，请联系客服！";
                }
                else
                {
                    //未删除，继续判断启用状态
                    if (isActived)
                    {
                        //己启用，跳转应用首页
                        Response.Redirect("default.aspx");
                    }
                    else
                    {
                        //账号停用
                        lblComment.Text = "当前账号已经停用，如有疑问，请联系客服！";
                    }
                }
            }
            else
            {
                //验证失败，请重试。。。
                lblComment.Text = "账号或密码错误，请确认后重试";
            }
        }


    }
}